package com.qf.controller;


import com.qf.POJO.Users;
import com.qf.service.UserService;
import com.qf.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public R login(@RequestBody Users user){
        System.out.println("----登录认证接口");
        return userService.checkLogin(user);
    }

    @PostMapping(value = "/register")
    public R register(@RequestBody Users user) {
        return userService.register(user);
    }


    @GetMapping("/hello")
    @PreAuthorize("hasAnyRole('ADMIN','USER')")
    public String hello() {
        return "hello, user";
    }


    @GetMapping("/list")
    @PreAuthorize("hasRole('ADMIN')")
    public String list() {
        return "hello, user";
    }

    @GetMapping("/delete")
    @PreAuthorize("hasRole('VIP')")
    public String delete() {
        return "hello, user";
    }

}